package br.com.cefetrn.apoena.converter;

import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
import org.hibernate.Session;

import br.com.cefetrn.apoena.view.component.HibernateSession;

import com.opensymphony.webwork.util.WebWorkTypeConverter;
import com.opensymphony.xwork.util.OgnlValueStack;

public abstract class AxConverterAPOENA  extends WebWorkTypeConverter{
	
	protected static final Log LOG = LogFactory.getLog(AxConverterAPOENA.class);
	
	
	@SuppressWarnings("unchecked")
	public abstract Object convertFromString(Map arg0, String[] arg1, Class arg2);

	@SuppressWarnings("unchecked")
	public abstract String convertToString(Map arg0, Object arg1);

	
	/**
	 * Get the Hibernate Session instance
	 */
	@SuppressWarnings("unchecked")
	protected Session getSession(Map arg0) throws HibernateException {
		
		OgnlValueStack valueStack =  (OgnlValueStack) arg0.get("com.opensymphony.xwork.util.OgnlValueStack.ValueStack");
		LOG.debug("attr OGNL value stack " + valueStack);
		
		HibernateSession hibernateSession = ((HibernateSession) valueStack.findValue("hibernateSession"));
		LOG.debug("hibernate session" + hibernateSession);
		
		Session object = hibernateSession.getSession();
		
		return object;
	}

}
